package com.eliauk.demo.controller.read;

import com.alibaba.excel.EasyExcel;
import com.eliauk.demo.dao.DemoDAO;
import com.eliauk.demo.entity.read.ConverterData;
import com.eliauk.demo.utils.excel.converter.CustomStringStringConverter;
import com.eliauk.demo.utils.excel.listener.Demo4DataListener;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

@RestController
@RequestMapping("demo4")
public class demo4Controller {

    @PostMapping("import")
    public String importData(MultipartFile file) throws IOException {
        InputStream in = file.getInputStream();
        EasyExcel.read(in, ConverterData.class,new Demo4DataListener(new DemoDAO()))
                .registerConverter(new CustomStringStringConverter())
                .sheet()
                .doRead();
        return "success";
    }

}
